********************************************************************************
********************************************************************************
********************************************************************************

	*** Losers of Automation: A Reservoir of Votes for the Radical Right? ***

						*** Last Update: 13 September 2018 ***

********************************************************************************
********************************************************************************
********************************************************************************
** NOTES: 
** Use datafile for European Social Survey Rounds 6 and 7 (Cumulative Wizard) and 8
** Merged with Arntz et al. (2016)'s share of high risk index.



********************************************************************************

gen wgt = pweight * dweight

cd "C:\Stata Output"

set more off

********************************************************************************

* A) Independent Variable - Risk of Automation

*A.1 Arntz et al. Measurement
recode country_p ///
	(1=1 "Austria") ///
	(2=2 "Belgium") ///
	(3=3 "Denmark") ///
	(4=4 "Finland") ///
	(5=5 "France") ///
	(6=6 "Germany") ///
	(7=7 "Italy") ///
	(8=8 "Netherlands") ///
	(9=9 "Norway") ///
	(10=10 "Sweden") ///
	(11=11 "United Kingdom") ///
	(else=.), gen(country_used)
	

label variable sh_highrisk "Risk of automation"



*A.2 Frey and Osborne (2017) adapted from Pajarinen and Rouvinen (2014)
	
	
// Automation (F&B)
gen computerisation =.

replace computerisation = 0.004 if (isco08==2351) | (isco08==1411) | (isco08==2265)
replace computerisation = 0.005 if (isco08==2266)
replace computerisation = 0.007 if (isco08==1345) | (isco08==1342) | (isco08==2634) ///
| (isco08==1344)
replace computerisation = 0.008 if (isco08==2330)
replace computerisation = 0.009 if (isco08==2221) | (isco08==2359)
replace computerisation = 0.011 if (isco08==2511)
replace computerisation = 0.012 if (isco08==2269) | (isco08==2262) | (isco08==2352) ///
| (isco08==2132)
replace computerisation = 0.014 if (isco08==1221) | (isco08==3341) | (isco08==2424) ///
| (isco08==2356)
replace computerisation = 0.015 if (isco08==1341)
replace computerisation = 0.016 if (isco08==3122)
replace computerisation = 0.017 if (isco08==2636) | (isco08==2145)
replace computerisation = 0.018 if (isco08==2161) | (isco08==1223) | (isco08==2143)
replace computerisation = 0.019 if (isco08==2142)
replace computerisation = 0.021 if (isco08==2264) | (isco08==2261) | (isco08==3431)
replace computerisation = 0.025 if (isco08==2133)
replace computerisation = 0.027 if (isco08==1222)
replace computerisation = 0.029 if (isco08==2163) | (isco08==2141)
replace computerisation = 0.030 if (isco08==1321) | (isco08==2522) | (isco08==2521) ///
| (isco08==3514)
replace computerisation = 0.032 if (isco08==2310)
replace computerisation = 0.034 if (isco08==2149)
replace computerisation = 0.035 if (isco08==2611) | (isco08==1330) | (isco08==3151)
replace computerisation = 0.037 if (isco08==3332)
replace computerisation = 0.038 if (isco08==2250) | (isco08==2651)
replace computerisation = 0.043 if (isco08==2653)
replace computerisation = 0.045 if (isco08==2652) | (isco08==2162)
replace computerisation = 0.046 if (isco08==3311)
replace computerisation = 0.047 if (isco08==1311) | (isco08==1312)
replace computerisation = 0.049 if (isco08==3258) | (isco08==2166)
replace computerisation = 0.050 if (isco08==7413)
replace computerisation = 0.055 if (isco08==3230)
replace computerisation = 0.059 if (isco08==1112)
replace computerisation = 0.060 if (isco08==2619)
replace computerisation = 0.061 if (isco08==3351) | (isco08==2113)
replace computerisation = 0.067 if (isco08==2653)
replace computerisation = 0.069 if (isco08==1211) | (isco08==3154)
replace computerisation = 0.070 if (isco08==2355)
replace computerisation = 0.071 if (isco08==1323) | (isco08==2421)
replace computerisation = 0.075 if (isco08==3423)
replace computerisation = 0.079 if (isco08==2342)
replace computerisation = 0.080 if (isco08==5311) | (isco08==2131)
replace computerisation = 0.082 if (isco08==2642)
replace computerisation = 0.083 if (isco08==1412)
replace computerisation = 0.084 if (isco08==1343)
replace computerisation = 0.085 if (isco08==2146)
replace computerisation = 0.086 if (isco08==2512)
replace computerisation = 0.087 if (isco08==2341) | (isco08==1120) | (isco08==5411)
replace computerisation = 0.100 if (isco08==2151)
replace computerisation = 0.106 if (isco08==2632)
replace computerisation = 0.110 if (isco08==2434)
replace computerisation = 0.114 if (isco08==1346)
replace computerisation = 0.118 if (isco08==2654)
replace computerisation = 0.122 if (isco08==2152)
replace computerisation = 0.130 if (isco08==3412) | (isco08==2354) | (isco08==5165) ///
| (isco08==2164)
replace computerisation = 0.132 if (isco08==2144)
replace computerisation = 0.134 if (isco08==2320)
replace computerisation = 0.140 if (isco08==2267)
replace computerisation = 0.142 if (isco08==1114)
replace computerisation = 0.148 if (isco08==2120)
replace computerisation = 0.150 if (isco08==7411) | (isco08==3152)
replace computerisation = 0.160 if (isco08==1420) | (isco08==5221)
replace computerisation = 0.163 if (isco08==2433)
replace computerisation = 0.169 if (isco08==3432)
replace computerisation = 0.170 if (isco08==3123) | (isco08==1431) | (isco08==3121)
replace computerisation = 0.172 if (isco08==3355)
replace computerisation = 0.173 if (isco08==2633)
replace computerisation = 0.180 if (isco08==2432) | (isco08==7541)
replace computerisation = 0.187 if (isco08==3259)
replace computerisation = 0.190 if (isco08==2111)
replace computerisation = 0.210 if (isco08==2643) | (isco08==2523)
replace computerisation = 0.220 if (isco08==2519) | (isco08==2529)
replace computerisation = 0.230 if (isco08==2422)
replace computerisation = 0.240 if (isco08==3116)
replace computerisation = 0.250 if (isco08==1322) | (isco08==1349) | (isco08==1439) ///
| (isco08==1213)
replace computerisation = 0.253 if (isco08==3153)
replace computerisation = 0.261 if (isco08==4221)
replace computerisation = 0.262 if (isco08==3211)
replace computerisation = 0.263 if (isco08==2423)
replace computerisation = 0.279 if (isco08==5169)
replace computerisation = 0.280 if (isco08==5222) | (isco08==3421)
replace computerisation = 0.296 if (isco08==2656)
replace computerisation = 0.298 if (isco08==3339)
replace computerisation = 0.300 if (isco08==3256)
replace computerisation = 0.313 if (isco08==5413)
replace computerisation = 0.322 if (isco08==2114)
replace computerisation = 0.324 if (isco08==2431) | (isco08==1212)
replace computerisation = 0.326 if (isco08==7127)
replace computerisation = 0.328 if (isco08==2641)
replace computerisation = 0.329 if (isco08==5141)
replace computerisation = 0.342 if (isco08==3119)
replace computerisation = 0.348 if (isco08==5113)
replace computerisation = 0.355 if (isco08==1219)
replace computerisation = 0.356 if (isco08==7232)
replace computerisation = 0.360 if (isco08==3324)
replace computerisation = 0.365 if (isco08==3434)
replace computerisation = 0.370 if (isco08==9122) | (isco08==2655) | (isco08==5163) ///
| (isco08==9311)
replace computerisation = 0.371 if (isco08==5142)
replace computerisation = 0.374 if (isco08==3422)
replace computerisation = 0.376 if (isco08==5111)
replace computerisation = 0.380 if (isco08==9321)
replace computerisation = 0.383 if (isco08==2621)
replace computerisation = 0.389 if (isco08==5112)
replace computerisation = 0.390 if (isco08==3353) | (isco08==7534)
replace computerisation = 0.392 if (isco08==3322)
replace computerisation = 0.402 if (isco08==5322)
replace computerisation = 0.405 if (isco08==2412)
replace computerisation = 0.410 if (isco08==8332) | (isco08==7535)
replace computerisation = 0.420 if (isco08==3143)
replace computerisation = 0.429 if (isco08==5245)
replace computerisation = 0.430 if (isco08==2631)
replace computerisation = 0.445 if (isco08==3240)
replace computerisation = 0.457 if (isco08==7312)
replace computerisation = 0.460 if (isco08==2413)
replace computerisation = 0.463 if (isco08==5419)
replace computerisation = 0.464 if (isco08==5164)
replace computerisation = 0.467 if (isco08==7314)
replace computerisation = 0.470 if (isco08==5321)
replace computerisation = 0.471 if (isco08==7234)
replace computerisation = 0.475 if (isco08==3214)
replace computerisation = 0.477 if (isco08==3115)
replace computerisation = 0.480 if (isco08==9611) | (isco08==7542) | (isco08==8344)
replace computerisation = 0.485 if (isco08==7126)
replace computerisation = 0.509 if (isco08==7549)
replace computerisation = 0.510 if (isco08==3312) | (isco08==5242)
replace computerisation = 0.513 if (isco08==3118)
replace computerisation = 0.514 if (isco08==9333)
replace computerisation = 0.520 if (isco08==2622) | (isco08==2612) | (isco08==7318) ///
| (isco08==7536)
replace computerisation = 0.530 if (isco08==3257)
replace computerisation = 0.532 if (isco08==7532)
replace computerisation = 0.535 if (isco08==3141)
replace computerisation = 0.536 if (isco08==7421)
replace computerisation = 0.538 if (isco08==3433) | (isco08==7311)
replace computerisation = 0.560 if (isco08==5312)
replace computerisation = 0.563 if (isco08==8312)
replace computerisation = 0.565 if (isco08==3112) | (isco08==7321)
replace computerisation = 0.568 if (isco08==8322)
replace computerisation = 0.570 if (isco08==6111)
replace computerisation = 0.573 if (isco08==9112)
replace computerisation = 0.575 if (isco08==3117) | (isco08==4224)
replace computerisation = 0.583 if (isco08==7422)
replace computerisation = 0.585 if (isco08==7119)
replace computerisation = 0.587 if (isco08==5329)
replace computerisation = 0.590 if (isco08==1324)
replace computerisation = 0.595 if (isco08==3251)
replace computerisation = 0.597 if (isco08==3132)
replace computerisation = 0.600 if (isco08==3521)
replace computerisation = 0.610 if (isco08==3435)
replace computerisation = 0.612 if (isco08==8331)
replace computerisation = 0.614 if (isco08==3131)
replace computerisation = 0.616 if (isco08==4212)
replace computerisation = 0.622 if (isco08==7233)
replace computerisation = 0.630 if (isco08==2165)
replace computerisation = 0.640 if (isco08==3333) | (isco08==9334)
replace computerisation = 0.643 if (isco08==3323) | (isco08==9622)
replace computerisation = 0.644 if (isco08==7412)
replace computerisation = 0.645 if (isco08==7231)
replace computerisation = 0.654 if (isco08==8343)
replace computerisation = 0.660 if (isco08==5153) | (isco08==9123)
replace computerisation = 0.662 if (isco08==3321)
replace computerisation = 0.670 if (isco08==6113) | (isco08==2112)
replace computerisation = 0.675 if (isco08==7515)
replace computerisation = 0.677 if (isco08==8311)
replace computerisation = 0.679 if (isco08==3334)
replace computerisation = 0.680 if (isco08==3343)
replace computerisation = 0.685 if (isco08==3212)
replace computerisation = 0.690 if (isco08==9111)
replace computerisation = 0.696 if (isco08==8111)
replace computerisation = 0.700 if (isco08==6222)
replace computerisation = 0.710 if (isco08==8157) | (isco08==3254)
replace computerisation = 0.713 if (isco08==7214)
replace computerisation = 0.720 if (isco08==7115)
replace computerisation = 0.725 if (isco08==8350)
replace computerisation = 0.730 if (isco08==7125) | (isco08==8152)
replace computerisation = 0.732 if (isco08==5120)
replace computerisation = 0.733 if (isco08==7544)
replace computerisation = 0.735 if (isco08==7124)
replace computerisation = 0.740 if (isco08==8171)
replace computerisation = 0.755 if (isco08==4222)
replace computerisation = 0.760 if (isco08==6130) | (isco08==6221) | (isco08==6121) ///
| (isco08==6122)
replace computerisation = 0.770 if (isco08==5132)
replace computerisation = 0.772 if (isco08==8113)
replace computerisation = 0.773 if (isco08==7222)
replace computerisation = 0.775 if (isco08==7212) | (isco08==3155)
replace computerisation = 0.780 if (isco08==3511) | (isco08==7213)
replace computerisation = 0.790 if (isco08==9629) | (isco08==8341)
replace computerisation = 0.792 if (isco08==6210)
replace computerisation = 0.800 if (isco08==9313) | (isco08==7132)
replace computerisation = 0.805 if (isco08==8211)
replace computerisation = 0.810 if (isco08==7131) | (isco08==7211) | (isco08==8143) ///
| (isco08==4131)
replace computerisation = 0.813 if (isco08==8181)
replace computerisation = 0.816 if (isco08==8160)
replace computerisation = 0.820 if (isco08==7112) | (isco08==7122)
replace computerisation = 0.822 if (isco08==8141)
replace computerisation = 0.825 if (isco08==3113) | (isco08==3134)
replace computerisation = 0.830 if (isco08==7322) | (isco08==9216) | (isco08==9129)
replace computerisation = 0.837 if (isco08==7315)
replace computerisation = 0.840 if (isco08==3114) | (isco08==9329) | (isco08==3522) ///
| (isco08==7531)
replace computerisation = 0.845 if (isco08==7511)
replace computerisation = 0.847 if (isco08==8131)
replace computerisation = 0.850 if (isco08==9412) | (isco08==3113)
replace computerisation = 0.857 if (isco08==4321)
replace computerisation = 0.860 if (isco08==4412) | (isco08==8172) | (isco08==7113)
replace computerisation = 0.870 if (isco08==9215)
replace computerisation = 0.871 if (isco08==7223)
replace computerisation = 0.880 if (isco08==9312) | (isco08==8121) | (isco08==4322) ///
| (isco08==8114) | (isco08==3135)
replace computerisation = 0.883 if (isco08==7114)
replace computerisation = 0.885 if (isco08==9621)
replace computerisation = 0.890 if (isco08==7512) | (isco08==7215) | (isco08==8153) ///
| (isco08==8112) | (isco08==8182)
replace computerisation = 0.892 if (isco08==8342)
replace computerisation = 0.895 if (isco08==5414) | (isco08==9623)
replace computerisation = 0.900 if (isco08==5131) | (isco08==7121) | (isco08==5230) ///
| (isco08==4416)
replace computerisation = 0.906 if (isco08==8142)
replace computerisation = 0.910 if (isco08==4225)
replace computerisation = 0.915 if (isco08==7522)
replace computerisation = 0.920 if (isco08==3213)
replace computerisation = 0.922 if (isco08==8212) | (isco08==8189)
replace computerisation = 0.925 if (isco08==7224)
replace computerisation = 0.930 if (isco08==5246) | (isco08==9612) | (isco08==7221) ///
| (isco08==3352)
replace computerisation = 0.940 if (isco08==3359) | (isco08==5151) | (isco08==4227) ///
| (isco08==5211) | (isco08==5243) | (isco08==9520) | (isco08==5152)
replace computerisation = 0.945 if (isco08==4415)
replace computerisation = 0.950 if (isco08==5223) | (isco08==9214) | (isco08==4214) ///
| (isco08==7313) | (isco08==7323)
replace computerisation = 0.953 if (isco08==3315)
replace computerisation = 0.957 if (isco08==2411)
replace computerisation = 0.960 if (isco08==4226) | (isco08==4323) | (isco08==8151)
replace computerisation = 0.965 if (isco08==4223) | (isco08==4211)
replace computerisation = 0.970 if (isco08==4110) | (isco08==4311) | (isco08==4313) ///
| (isco08==5249) | (isco08==3142) | (isco08==4411) | (isco08==8154) | (isco08==8219) ///
| (isco08==8156)
replace computerisation = 0.980 if (isco08==3313) | (isco08==8183) | (isco08==3342)
replace computerisation = 0.985 if (isco08==3331)
replace computerisation = 0.990 if (isco08==5244) | (isco08==4132) | (isco08==8132)

label variable computerisation "Probability of Computerisation"




********************************************************************************

* B) Control Variables 

// Income
recode hinctnta ///
	(1=1 "1st Decile") ///
	(2=2 "2nd Decile") ///
	(3=3 "3rd Decile") ///
	(4=4 "4th Decile") ///
	(5=5 "5th Decile") ///
	(6=6 "6th Decile") ///
	(7=7 "7th Decile") ///
	(8=8 "8th Decile") ///
	(9=9 "9th Decile") ///
	(10=10 "10th Decile") ///
	(else=.), gen(income)
label variable income "Income by Decile"



// Year fixed effect
recode essround ///
	(6=1 "2012") ///
	(7=2 "2014") ///
	(8=3 "2016") ///
	(else=.), ///
	gen(year)



// Source of income
recode hincsrca ///
	(1 2=1 "Wages or self-employed income (except farming)" ) ///
	(5 = 2 "Unemployment benefits") ///
	(4 = 3 "Pensions") ///
	(else=.), ///
	gen(inc_src)
	


// Age
recode agea ///
	(999=.), gen(age)
label variable age "Age"


// Gender
recode gndr ///
	(1=0 "Male") ///
	(2=1 "Female") ///
	(else=.), gen(gender_b)
label variable gender_b "Gender"


// Education
recode edulvlb ///
	(0/323=1 "Upper secondary or lower") ///
	(412/423=2 "Post-sec non-tertiary") ///
	(510/520=3 "Short-cycle tertiary") ///
	(610/620=4 "Bachelor's or equivalent") ///
	(710/800=5 "Master's or higher") ///
	(else=.), ///
	gen(education)


// Union Membership
recode mbtru ///
	(1=1 "Union member") ///
	(else=0 "Not union member"), ///
	gen(union)
	
	
// Belong to ethnic minority
recode blgetmg ///
	(1=0 "Belong to ethnic minority") ///
	(2=1 "Do not belong to ethnic minority") ///
	(else=.), gen(ethnic_min)
	
	
	
// Industry sectors 
// recoded according to EUROSTAT NACE Rev. 2 (2008) pg. 57
recode nacer2 ///
	(1/3=1 "A: Agriculture, Forestry and Fishing") ///
	(5/9=2 "B: Mining and Quarrying") ///
	(10/33=3 "C: Manufacturing") ///
	(35=4 "D: Electricity, Gas, Steam and Air Conditioning Supply") ///
	(36/39=5 "E: Water Supply, Sewerage, Waste Management and Remediation Activities") ///
	(41/43=6 "F: Construction") ///
	(45/47=7 "G: Wholesale and Retail Trade; Repair of Motor Vehicles and Motorcycles") ///
	(49/53=8 "H: Transporation and Storage") ///
	(55/53=9 "I: Accommodation and Food Service Activities") ///
	(58/63=10 "J: Information and Communication") ///
	(64/66=11 "K: Financial and Insurance Activities") ///
	(68=12 "L: Real Estate Activities") ///
	(69/75=13 "M: Professional, Scientific and Technical Activities") ///
	(77/82=14 "N: Administrative and Support Service Activities") ///
	(84=15 "O: Public Administration and Defence; Compulsory Social Security") ///
	(85=16 "P: Education") ///
	(86/88=17 "Q: Human Health and Social Work Activities") ///
	(90/93=18 "R: Arts, Entertainment and Recreation") ///
	(94/96=19 "S: Other Service Activities") ///
	(97/98=20 "T: Activities of Households as Employers; Undifferentiated Goods-And Services-Producing Activities of Households for Own Use") ///
	(99=21 "U: Activities of Extraterritorial Organisations and Bodies") ///
	(else=.), ///
	gen(sector)

	
// Work organisation type
recode tporgwk ///
	(1 2 3=1 "Government and public sector") ///
	(4=2 "Private firm") ///
	(5=3 "Self employed") ///
	(else=.), ///
	gen(org_sec)
	

// Contract type
recode wrkctra ///
	(1=0 "Unlimited") ///
	(2=1 "Limited") ///
	(else=.), ///
	gen(emp_ctra)
	
	
// Income perception 	
label variable hincfel "Living on present income"
label define hincfel ///
	1 "Comfortable" ///
	2 "Coping" ///
	3 "Difficult" ///
	4 "Very difficult", ///
	replace
	

*********************************************************************************************************************************************

* C) Dependent Variable - Electoral Behaviour

* C.1) Categorical DV
gen vote_after_a=.

// Radical Right
replace vote_after_a=1 if ///
	[(prtvtbat==3) | (prtvtbat==4) | ///
	(prtvtcbe==7) | (prtvtcbe==11) | ///
	(prtvtcdk==5) | ///
	(prtvtcfi==4) |  (prtvtdfi==4) | ///
	(prtvtcfr==2) | ///
	(prtvdde1==6) | (prtvdde1==7) | (prtvede1==6) | (prtvede1==8) | ///
	(prtvtbit==9) | ///
	(prtvtenl==3) | (prtvtfnl==3) | ///
	(prtvtbno==8) | (prtvtano==8) | ///
	(prtvtbse==10) | ///
	(prtvtbgb==7)]
// FPO & BZO [Austria]; 
// VB & FN [Belgium];
// DF [Denmark]
// PS [Finland]; 
// FN [France]
// Rep, NPD, AfD [Germany]
// Lega Nord [Itay]
// PVV [Netherlands]
// FrP [Norway]
// SD [Sweden]; 
// UKIP [UK]



// Radical Left
replace vote_after_a=2 if ///
	[(prtvtbat==6) | ///
	(prtvtcbe==6) | ///
	(prtvtcdk==4) | (prtvtcdk==9) | ///
	(prtvtcfi==14) | (prtvtcfi==15) | (prtvtdfi==12) | (prtvtdfi==13) |  ///
	(prtvtcfr==5) | (prtvtcfr==6) | (prtvtcfr==7) | ///
	(prtvdde1==5) |  (prtvede1==3) | ///
	(prtvtbit==3) | ///
	(prtvtenl==5) | (prtvtfnl==4) | ///
	(prtvtbno==2) | (prtvtbno==1) | (prtvtano==2) | (prtvtano==1) | ///
	(prtvtces==4) | ///
	(prtvtbse==7)]
// KPO [Austria]; 
// PvdA+ [Belgium];
// Socialistik Folkeparti, Red & Green Alliance [Denmark]
// VAS & Communist Party [Finland]; 
// Ligue Communiste Revolutionaire, LO, FDG, Parti Radical de Gauche [France]
// Die Linke [Germany]
// RC [Itay]
// SP [Netherlands]
// SV & RyDT [Norway]
// IU [Spain]
// Vanster [Sweden]; 



// Major Left
replace vote_after_a=3 if ///
	[(prtvtbat==1) | ///
	(prtvtcbe==5) | (prtvtcbe==13) | ///
	(prtvtcdk==1) | ///
	(prtvtcfi==13) | (prtvtdfi==11) | ///
	(prtvtcfr==9) | ///
	(prtvdde1==1) | (prtvede1==2) | ///
	(prtvtbit==1) | ///
	(prtvtenl==2) | (prtvtfnl==2) | ///
	(prtvtbno==3) | (prtvtano==3) | ///
	(prtvtbse==6) | ///
	(prtvtbgb==2)]
// SPO [Austria]; 
// SPA, PS [Belgium];
// Socialdemokraterne [Denmark]
// SDP [Finland]; 
// PS [France]
// SPD [Germany]
// PD [Itay]
// PvdA [Netherlands]
// A [Norway]
// Socialdemokraterna [Sweden]; 
// Labour [UK]



// Major Right
replace vote_after_a=4 if ///
	[(prtvtbat==2) | ///
	(prtvtcbe==9) | (prtvtcbe==8) | (prtvtcbe==12) | (prtvtcbe==2) | (prtvtcbe==3) | ///
	(prtvtcdk==7) | ///
	(prtvtcfi==1) | (prtvtcfi==3) | (prtvtdfi==1) | (prtvtdfi==3) | ///
	(prtvtcfr==10) | ///
	(prtvdde1==2) | (prtvede1==1) | ///
	(prtvtbit==6) | (prtvtbit==8) | ///
	(prtvtenl==1) | (prtvtenl==4) | (prtvtfnl==1) | (prtvtfnl==5) | ///
	(prtvtbno==7) | (prtvtano==7) | ///
	(prtvtbse==5) | ///
	(prtvtbgb==1)]
// OVP [Austria]; 
// CDH, VLD, MR, CDV, NVA [Belgium];
// Venstre [Denmark]
// KOK, KESK [Finland]; 
// UMP [France]
// CDU/CSU [Germany]
// UDC, PDL [Itay]
// VVD, CDA [Netherlands]
// H [Norway]
// Moderara [Sweden]; 
// Conservative [UK]



// Did not vote
replace vote_after_a=5 if (vote==2) 


label variable vote_after_a "Party Voted For"
label define vote_after_a ///
	1 "Radical Right" ///
	2 "Radical Left" ///
	3 "Major Left" ///
	4 "Major Right" ///
	5 "Did Not Vote"



********************************************************************************
********************************************************************************
********************************************************************************

*** D) Regression Outputs
* Collinearity Test
collin ///
	vote_after_a ///
	sh_highrisk ///
	hincfel ///
	age ///
	gender ///
	education ///
	rlgdgr ///
	union ///
	ethnic_min ///
	income ///
	year ///
	country_used



* D.1) Stepwise regression
// Arntz et al. Measurement without Interaction 
// No interaction effects
eststo, title("Logit Regression"): ///
	mlogit vote_after_a ///
	c.sh_highrisk ib3.hincfel ///
	c.age i.gender_b c.education ///
	c.rlgdgr i.union i.ethnic_min ///
	c.income ///
	i.year ///
	i.country_used ///
	[pweight=dweight], ///
	cluster(country_used) base(1) 
	
	
// Regression Table Output
esttab using example.csv, replace nogap ///
star( + 0.10 * 0.05 ** 0.01 *** 0.001) ///
b se(a3) ///
nonumbers mtitles("RL" "ML" "MR" "Did not vote") /// 
stats(N, layout(`""@ (@)""' @ @)) varwidth(40) unstack label ///
nobaselevels /// 
noomitted title(Logit Regressions)	
	
	
	
// D.1.2) Margins (average marginal effects)
margins, ///
	dydx(sh_highrisk) ///
	atmeans ///
	predict(outcome(1)) ///
	saving(1_1.gph, replace)
	
	
margins, ///
	dydx(sh_highrisk) ///
	atmeans ///
	predict(outcome(3)) ///
	saving(1_3.gph, replace)
	
	
margins, ///
	dydx(sh_highrisk) ///
	atmeans ///
	predict(outcome(4)) ///
	saving(1_4.gph, replace)
	

combomarginsplot ///
	1_1.gph 1_3.gph 1_4.gph, ///
	horizontal ///
	xline(0) ///
	recast(scatter) ///
	yscale(reverse) ///
	title("Average Marginal Effects of Risk of Automation") 
	
	
	
// Average marginal effects Output
* Post-estimation Output
foreach o in 1 2 3 4   {
     quietly margins, ///
	 atmeans ///
	 dydx(sh_highrisk) ///
	 predict(outcome(`o')) ///
		post
     eststo, title(Outcome `o')
	 estimates restore est1
     
 }
 
eststo drop est1


esttab using example.csv, replace nogap ///
star( + 0.10 * 0.05 ** 0.01 *** 0.001) ///
b(a3) se(a3) ///
nonumbers mtitles("RR" "ML" "MR") /// 
stats(N, layout(`""@ (@)""' @ @)) varwidth(65) unstack label ///
title(Adjusted Marginal Effects)

	

	
// D.1.3) Margins by range of IV
***Graphing predicted probabilities with no interaction effects 
	//!!!NOTE: need to download plottig graph scheme, type: "findit plottig"!!!
 margins, atmeans at(sh_highrisk=(0(0.05)0.6)) predict(outcome(1))
     marginsplot , recast(line) recastci(rline) ci1opts(fintensity(50) lpattern(dot)) xti(Risk of automation) yti(Pr) ti("Vote Radical Right") scheme(plottig) saving(RR.gph, replace)
 margins, atmeans at(sh_highrisk=(0(0.05)0.6)) predict(outcome(2))
     marginsplot , recast(line) recastci(rline) ci1opts(fintensity(50) lpattern(dot)) xti(Risk of automation) yti(Pr) ti("Vote Radical Left") scheme(plottig) saving(RL.gph, replace)
 margins, atmeans at(sh_highrisk=(0(0.05)0.6)) predict(outcome(3))
     marginsplot , recast(line) recastci(rline) ci1opts(fintensity(50) lpattern(dot)) xti(Risk of automation) yti(Pr) ti("Vote Major Left") scheme(plottig) saving(ML.gph, replace)
 margins, atmeans at(sh_highrisk=(0(0.05)0.6)) predict(outcome(4))
     marginsplot , recast(line) recastci(rline) ci1opts(fintensity(50) lpattern(dot)) xti(Risk of automation) yti(Pr) ti("Vote Major Right") scheme(plottig) saving(MR.gph, replace)
 margins, atmeans at(sh_highrisk=(0(0.05)0.6)) predict(outcome(5))
     marginsplot , recast(line) recastci(rline) ci1opts(fintensity(50) lpattern(dot)) xti(Risk of automation) yti(Pr) ti("Abstain") scheme(plottig) saving(Abs.gph, replace)
 
graph combine RR.gph ML.gph MR.gph RL.gph, scheme(plottig)
graph export vote.pdf, replace	



// Marginal effects (predicted probailities) output
* Post-estimation Output
foreach o in 1 2 3 4   {
     quietly margins, ///
	 atmeans ///
	 at(sh_highrisk=(0(0.05)0.6)) ///
	 predict(outcome(`o')) ///
		post
     eststo, title(Outcome `o')
	 estimates restore est1
     
 }
 
eststo drop est1


esttab using example.csv, replace nogap ///
star( + 0.10 * 0.05 ** 0.01 *** 0.001) ///
b(a3) se(a3) ///
nonumbers mtitles("RR" "ML" "MR") /// 
stats(N, layout(`""@ (@)""' @ @)) varwidth(65) unstack label ///
title(Predicted Probability of Risk of Automation)





*******************************************************************************
	
// D2.1) BASE MODEL with Interaction effects - Design weights applied
eststo, title("Logit Regression"): ///
	mlogit vote_after_a ///
	c.sh_highrisk##ib3.hincfel ///
	c.age i.gender_b c.education ///
	c.rlgdgr i.union i.ethnic_min ///
	c.income ///
	i.year ///
	i.country_used ///
	[pweight=dweight], ///
	cluster(country_used) base(1) 
	
	
// Regression Table Output
esttab using example.csv, replace nogap ///
star( + 0.10 * 0.05 ** 0.01 *** 0.001) ///
b se(a3) ///
nonumbers mtitles("RL" "ML" "MR" "Did not vote") /// 
stats(N, layout(`""@ (@)""' @ @)) varwidth(40) unstack label ///
nobaselevels /// 
noomitted title(Logit Regressions)	
	
	
***Graphing predicted probabilities with interaction effects 
	//!!!NOTE: need to download plottig graph scheme, type: "findit plottig"!!!
 margins, atmeans at(sh_highrisk=(0(0.05)0.6)) over(hincfel) predict(outcome(1))
     marginsplot , recast(line) recastci(rline) ci1opts(fintensity(50) lpattern(blank)) ///
	 plot1opts(lpattern(line) lcolor(black)) ///
	 plot2opts(lpattern(dash) lcolor(red)) ///
	 plot3opts(lpattern(dash_dot) lcolor(blue)) ///
	 plot4opts(lpattern(longdash) lcolor(green)) ///
	 ci2opts(fintensity(50) lpattern(blank)) ///
	 ci3opts(fintensity(50) lpattern(blank)) ///
	 ci4opts(fintensity(50) lpattern(blank)) ///
	 xti(Risk of automation) yti(Pr) ti("Vote Radical Right") scheme(plottig) legend(rows(1)) saving(iRR.gph, replace)
 margins, atmeans at(sh_highrisk=(0(0.05)0.6)) over(hincfel) predict(outcome(2))
     marginsplot , recast(line) recastci(rline) ci1opts(fintensity(50) lpattern(blank)) ///
	 plot1opts(lpattern(line) lcolor(black)) ///
	 plot2opts(lpattern(dash) lcolor(red)) ///
	 plot3opts(lpattern(dash_dot) lcolor(blue)) ///
	 plot4opts(lpattern(longdash) lcolor(green)) ///
	 ci2opts(fintensity(50) lpattern(blank)) ///
	 ci3opts(fintensity(50) lpattern(blank)) ///
	 ci4opts(fintensity(50) lpattern(blank)) ///
	 xti(Risk of automation) yti(Pr) ti("Vote Radical Left") scheme(plottig) saving(iRL.gph, replace)
 margins, atmeans at(sh_highrisk=(0(0.05)0.6)) over(hincfel) predict(outcome(3))
     marginsplot , recast(line) recastci(rline) ci1opts(fintensity(50) lpattern(blank)) ///
	 plot1opts(lpattern(line) lcolor(black)) ///
	 plot2opts(lpattern(dash) lcolor(red)) ///
	 plot3opts(lpattern(dash_dot) lcolor(blue)) ///
	 plot4opts(lpattern(longdash) lcolor(green)) ///
	 ci2opts(fintensity(50) lpattern(blank)) ///
	 ci3opts(fintensity(50) lpattern(blank)) ///
	 ci4opts(fintensity(50) lpattern(blank)) ///
	 xti(Risk of automation) yti(Pr) ti("Vote Major Left") scheme(plottig) saving(iML.gph, replace)
 margins, atmeans at(sh_highrisk=(0(0.05)0.6)) over(hincfel) predict(outcome(4))
     marginsplot , recast(line) recastci(rline) ci1opts(fintensity(50) lpattern(blank)) ///
	 plot1opts(lpattern(line) lcolor(black)) ///
	 plot2opts(lpattern(dash) lcolor(red)) ///
	 plot3opts(lpattern(dash_dot) lcolor(blue)) ///
	 plot4opts(lpattern(longdash) lcolor(green)) ///
	 ci2opts(fintensity(50) lpattern(blank)) ///
	 ci3opts(fintensity(50) lpattern(blank)) ///
	 ci4opts(fintensity(50) lpattern(blank)) ///
	 xti(Risk of automation) yti(Pr) ti("Vote Major Right") scheme(plottig) saving(iMR.gph, replace)
 margins, atmeans at(sh_highrisk=(0(0.05)0.6)) over(hincfel) predict(outcome(5))
     marginsplot , recast(line) recastci(rline) ci1opts(fintensity(50) lpattern(blank)) ///
	 plot1opts(lpattern(line) lcolor(black)) ///
	 plot2opts(lpattern(dash) lcolor(red)) ///
	 plot3opts(lpattern(dash_dot) lcolor(blue)) ///
	 plot4opts(lpattern(longdash) lcolor(green)) ///
	 ci2opts(fintensity(50) lpattern(blank)) ///
	 ci3opts(fintensity(50) lpattern(blank)) ///
	 ci4opts(fintensity(50) lpattern(blank)) ///
	 xti(Risk of automation) yti(Pr) ti("Abstain") scheme(plottig) saving(iAbs.gph, replace)
 
grc1leg iRR.gph iRL.gph iMR.gph iML.gph iAbs.gph, legendfrom(iRR.gph) iscale(0.8) scheme(plottig) 
graph export vote_interacted.pdf, replace	

graph combine iRR.gph iRL.gph iML.gph iMR.gph iAbs.gph, scheme(plottig) 

	
	



// Post-Estimation (Margins - predicted probabilities)
* Post-estimation Output
foreach o in 1 2 3 4 5 {
     quietly margins, ///
	 atmeans ///
	 at(sh_highrisk=(0(0.05)0.6)) ///
	 by(hincfel)  ///
	 predict(outcome(`o')) ///
		post
     eststo, title(Outcome `o')
	 estimates restore est1
     
 }
 
eststo drop est1


esttab using example.csv, replace nogap ///
star( + 0.10 * 0.05 ** 0.01 *** 0.001) ///
b(a3) se(a3) ///
nonumbers mtitles("RR" "RL" "ML" "MR" "Did not vote") /// 
stats(N, layout(`""@ (@)""' @ @)) varwidth(65) unstack label ///
title(Adjusted Marginal Effects)
	


// D.2.3) Figures for Marginal Effects (Unit change - dydx)
margins, ///
	dydx(sh_highrisk) ///
	atmeans ///
	within(hincfel) ///
	predict(outcome(1)) ///

marginsplot, ///
	recast(scatter) ///
	title("Vote Radical Right") ///
	xtitle("Average Marginal Effect") ///
	ytitle("Feeling of Income Security") ///
	xline(0) ///
	yscale(reverse) ///
	horizontal ///
	scheme(plottig) ///
	saving(2_1, replace)
	
	
margins, ///
	dydx(sh_highrisk) ///
	atmeans ///
	within(hincfel) ///
	predict(outcome(2)) ///

marginsplot, ///
	recast(scatter) ///
	title("Vote Radical Left") ///
	xtitle("Average Marginal Effect") ///
	ytitle("Feeling of Income Security") ///
	xline(0) ///
	yscale(reverse) ///
	horizontal ///
	scheme(plottig) ///
	saving(2_2, replace)
	
margins, ///
	dydx(sh_highrisk) ///
	atmeans ///
	within(hincfel) ///
	predict(outcome(3))
	
marginsplot, ///
	recast(scatter) ///
	title("Vote Major Left") ///
	xtitle("Average Marginal Effect") ///
	ytitle("Feeling of Income Security") ///
	xline(0) ///
	yscale(reverse) ///
	horizontal ///
	scheme(plottig) ///
	saving(2_3, replace)
	
margins, ///
	dydx(sh_highrisk) ///
	atmeans ///
	within(hincfel) ///
	predict(outcome(4))
	
marginsplot, ///
	recast(scatter) ///
	title("Vote Major Right") ///
	xtitle("Average Marginal Effect") ///
	ytitle("Feeling of Income Security") ///
	xline(0) ///
	yscale(reverse) ///
	horizontal ///
	scheme(plottig) ///
	saving(2_4, replace)

	
graph combine ///
	2_1.gph 2_2.gph 2_3.gph 2_4.gph, ///
	scheme(plottig)
	
	
// Post-Estimation
* Post-estimation Output
foreach o in 1 2 3 4  {
     quietly margins, ///
	 atmeans ///
	 dydx(sh_highrisk) ///
	 by(hincfel)  ///
	 predict(outcome(`o')) ///
		post
     eststo, title(Outcome `o')
	 estimates restore est1
     
 }
 
eststo drop est1


esttab using example.csv, replace nogap ///
star( + 0.10 * 0.05 ** 0.01 *** 0.001) ///
b(a3) se(a3) ///
nonumbers mtitles("RR" "RL" "ML" "MR") /// 
stats(N, layout(`""@ (@)""' @ @)) varwidth(65) unstack label ///
title(Adjusted Marginal Effects)


	
	
	
********************************************************************************	
********************************************************************************

* E) Robustness Checks
// E1) Base Model with population weights
eststo, title("Logit Regression"): ///
mlogit vote_after_a ///
	c.sh_highrisk##ib3.hincfel ///
	c.age i.gender_b c.education ///
	c.rlgdgr i.union i.ethnic_min ///
	c.income ///
	i.year ///
	i.country_used ///
	[pweight=wgt], ///
	cluster(country_used) base(1) 
	
	
	

// E1a) Post-Estimation
* Post-estimation Output
foreach o in 1 2 3 4 5  {
     quietly margins, ///
	 atmeans ///
	 dydx(sh_highrisk) by(hincfel) ///
	 predict(outcome(`o')) ///
		post
     eststo, title(Outcome `o')
	 estimates restore est1
     
 }
 
eststo drop est1


esttab using example.csv, replace nogap ///
star( + 0.10 * 0.05 ** 0.01 *** 0.001) ///
b(a3) se(a3) ///
nonumbers mtitles("RR" "RL" "ML" "MR" "Did not vote") /// 
stats(N, layout(`""@ (@)""' @ @)) varwidth(65) unstack label ///
title(Adjusted Marginal Effects)
	

****	
// E2) Base Model without country dummies
eststo, title("Logit Regression"): ///
	mlogit vote_after_a ///
	c.sh_highrisk##ib3.hincfel ///
	c.age i.gender_b c.education ///
	c.rlgdgr i.union i.ethnic_min ///
	c.income ///
	i.year ///
	[pweight=dweight], ///
	cluster(country_used) base(1) 




***
// E2a) Post-Estimation
* Post-estimation Output
foreach o in 1 2 3 4 5  {
     quietly margins, ///
	 atmeans ///
	 dydx(sh_highrisk) by(hincfel) ///
	 predict(outcome(`o')) ///
		post
     eststo, title(Outcome `o')
	 estimates restore est1
     
 }
 
eststo drop est1


esttab using example.csv, replace nogap ///
star( + 0.10 * 0.05 ** 0.01 *** 0.001) ///
b(a3) se(a3) ///
nonumbers mtitles("RR" "RL" "ML" "MR" "Did not vote") /// 
stats(N, layout(`""@ (@)""' @ @)) varwidth(65) unstack label ///
title(Adjusted Marginal Effects)



***
// E3) Base Model without income
eststo, title("Logit Regression"): ///
	mlogit vote_after_a ///
	c.sh_highrisk##ib3.hincfel ///
	c.age i.gender_b c.education ///
	c.rlgdgr i.union i.ethnic_min ///
	i.year ///
	i.country_used ///
	[pweight=dweight], ///
	cluster(country_used) base(1) 
	


// E3a) Post-Estimation
* Post-estimation Output
foreach o in 1 2 3 4 5  {
     quietly margins, ///
	 atmeans ///
	 dydx(sh_highrisk) by(hincfel) ///
	 predict(outcome(`o')) ///
		post
     eststo, title(Outcome `o')
	 estimates restore est1
     
 }
 
eststo drop est1


esttab using example.csv, replace nogap ///
star( + 0.10 * 0.05 ** 0.01 *** 0.001) ///
b(a3) se(a3) ///
nonumbers mtitles("RR" "RL" "ML" "MR" "Did not vote") /// 
stats(N, layout(`""@ (@)""' @ @)) varwidth(65) unstack label ///
title(Adjusted Marginal Effects)



***
// E4) Base Model with population weights and country dummies omitted
eststo, title("Logit Regression"): ///
	mlogit vote_after_a ///
	c.sh_highrisk##ib3.hincfel ///
	c.age i.gender_b c.education ///
	c.rlgdgr i.union i.ethnic_min ///
	c.income ///
	i.year ///
	[pweight=wgt], ///
	cluster(country_used) base(1) 
	

// E4a) Post-Estimation
* Post-estimation Output
* Post-estimation Output
foreach o in 1 2 3 4 5  {
     quietly margins, ///
	 atmeans ///
	 dydx(sh_highrisk) by(hincfel) ///
	 predict(outcome(`o')) ///
		post
     eststo, title(Outcome `o')
	 estimates restore est1
     
 }
 
eststo drop est1


esttab using example.csv, replace nogap ///
star( + 0.10 * 0.05 ** 0.01 *** 0.001) ///
b(a3) se(a3) ///
nonumbers mtitles("RR" "RL" "ML" "MR" "Did not vote") /// 
stats(N, layout(`""@ (@)""' @ @)) varwidth(65) unstack label ///
title(Adjusted Marginal Effects)



***
// E5) Base Model with population weights and income omitted
eststo, title("Logit Regression"): ///
	mlogit vote_after_a ///
	c.sh_highrisk##ib3.hincfel ///
	c.age i.gender_b c.education ///
	c.rlgdgr i.union i.ethnic_min ///
	i.country_used ///
	i.year ///
	[pweight=wgt], ///
	cluster(country_used) base(1) 
	



// E5a) Post-Estimation
* Post-estimation Output
* Post-estimation Output
foreach o in 1 2 3 4 5  {
     quietly margins, ///
	 atmeans ///
	 dydx(sh_highrisk) by(hincfel) ///
	 predict(outcome(`o')) ///
		post
     eststo, title(Outcome `o')
	 estimates restore est1
     
 }
 
eststo drop est1


esttab using example.csv, replace nogap ///
star( + 0.10 * 0.05 ** 0.01 *** 0.001) ///
b(a3) se(a3) ///
nonumbers mtitles("RR" "RL" "ML" "MR" "Did not vote") /// 
stats(N, layout(`""@ (@)""' @ @)) varwidth(65) unstack label ///
title(Adjusted Marginal Effects)



***
// E6) Control for industry sector
eststo, title("Logit Regression"): ///
	mlogit vote_after_a ///
	c.sh_highrisk##ib3.hincfel ///
	c.age i.gender_b c.education ///
	c.rlgdgr i.union i.ethnic_min ///
	c.income ///
	i.year ///
	i.country_used ///
	i.sector ///
	[pweight=dweight], ///
	cluster(country_used) base(1) 

	
* Post-estimation Output
foreach o in 1 2 3 4 5  {
     quietly margins, ///
	 atmeans ///
	 dydx(sh_highrisk) by(hincfel) ///
	 predict(outcome(`o')) ///
		post
     eststo, title(Outcome `o')
	 estimates restore est1
     
 }
 
eststo drop est1


esttab using example.csv, replace nogap ///
star( + 0.10 * 0.05 ** 0.01 *** 0.001) ///
b(a3) se(a3) ///
nonumbers mtitles("RR" "RL" "ML" "MR" "Did not vote") /// 
stats(N, layout(`""@ (@)""' @ @)) varwidth(65) unstack label ///
title(Adjusted Marginal Effects)



***
// E7) Control for type of organisation worked for
eststo, title("Logit Regression"): ///
	mlogit vote_after_a ///
	c.sh_highrisk##ib3.hincfel ///
	c.age i.gender_b c.education ///
	c.rlgdgr i.union i.ethnic_min ///
	c.income ///
	i.year ///
	i.country_used ///
	i.org_sec ///
	[pweight=dweight], ///
	cluster(country_used) base(1) 

	
* Post-estimation Output
foreach o in 1 2 3 4 5  {
     quietly margins, ///
	 atmeans ///
	 dydx(sh_highrisk) by(hincfel) ///
	 predict(outcome(`o')) ///
		post
     eststo, title(Outcome `o')
	 estimates restore est1
     
 }
 
eststo drop est1


esttab using example.csv, replace nogap ///
star( + 0.10 * 0.05 ** 0.01 *** 0.001) ///
b(a3) se(a3) ///
nonumbers mtitles("RR" "RL" "ML" "MR" "Did not vote") /// 
stats(N, layout(`""@ (@)""' @ @)) varwidth(65) unstack label ///
title(Adjusted Marginal Effects)



***
// E8) Computerisation - Frey and Osborne
eststo, title("Logit Regression"): ///
	mlogit vote_after_a ///
	c.computerisation##ib3.hincfel ///
	c.age i.gender_b c.education ///
	c.rlgdgr i.union i.ethnic_min ///
	c.income ///
	i.year ///
	i.country_used ///
	i.sector ///
	[pweight=dweight], ///
	cluster(country_used) base(1) 

	
* Post-estimation Output
foreach o in 1 2 3 4 5  {
     quietly margins, ///
	 atmeans ///
	 dydx(computerisation) by(hincfel) ///
	 predict(outcome(`o')) ///
		post
     eststo, title(Outcome `o')
	 estimates restore est1
     
 }
 
eststo drop est1


esttab using example.csv, replace nogap ///
star( + 0.10 * 0.05 ** 0.01 *** 0.001) ///
b(a3) se(a3) ///
nonumbers mtitles("RR" "RL" "ML" "MR" "Did not vote") /// 
stats(N, layout(`""@ (@)""' @ @)) varwidth(65) unstack label ///
title(Adjusted Marginal Effects)




***
// E9) Attitudes towards immigrants
eststo, title("Logit Regression"): ///
	mlogit vote_after_a ///
	c.sh_highrisk##ib3.hincfel ///
	c.age i.gender_b c.education ///
	c.rlgdgr i.union i.ethnic_min ///
	c.income ///
	i.year ///
	i.country_used ///
	c.imwbcnt ///
	[pweight=dweight], ///
	cluster(country_used) base(1) 

	
* Post-estimation Output
foreach o in 1 2 3 4 5  {
     quietly margins, ///
	 atmeans ///
	 dydx(sh_highrisk) by(hincfel) ///
	 predict(outcome(`o')) ///
		post
     eststo, title(Outcome `o')
	 estimates restore est1
     
 }
 
eststo drop est1


esttab using example.csv, replace nogap ///
star( + 0.10 * 0.05 ** 0.01 *** 0.001) ///
b(a3) se(a3) ///
nonumbers mtitles("RR" "RL" "ML" "MR" "Did not vote") /// 
stats(N, layout(`""@ (@)""' @ @)) varwidth(65) unstack label ///
title(Adjusted Marginal Effects)




***
// E10) Attitudes towards EU
eststo, title("Logit Regression"): ///
	mlogit vote_after_a ///
	c.sh_highrisk##ib3.hincfel ///
	c.age i.gender_b c.education ///
	c.rlgdgr i.union i.ethnic_min ///
	c.income ///
	i.year ///
	i.country_used ///
	c.euftf ///
	[pweight=dweight], ///
	cluster(country_used) base(1) 

	
* Post-estimation Output
foreach o in 1 2 3 4 5  {
     quietly margins, ///
	 atmeans ///
	 dydx(sh_highrisk) by(hincfel) ///
	 predict(outcome(`o')) ///
		post
     eststo, title(Outcome `o')
	 estimates restore est1
     
 }
 
eststo drop est1

esttab using example.csv, replace nogap ///
star( + 0.10 * 0.05 ** 0.01 *** 0.001) ///
b(a3) se(a3) ///
nonumbers mtitles("RR" "RL" "ML" "MR" "Did not vote") /// 
stats(N, layout(`""@ (@)""' @ @)) varwidth(65) unstack label ///
title(Adjusted Marginal Effects)



***
// E11) Sociocultural and socioeconomic attitudes
// Operationalised as government's role on income differences and gay rights
eststo, title("Logit Regression"): ///
	mlogit vote_after_a ///
	c.sh_highrisk##ib3.hincfel ///
	c.age i.gender_b c.education ///
	c.rlgdgr i.union i.ethnic_min ///
	c.income ///
	i.year ///
	i.country_used ///
	c.gincdif c.freehms ///
	[pweight=dweight], ///
	cluster(country_used) base(1) 

	
* Post-estimation Output
foreach o in 1 2 3 4 5  {
     quietly margins, ///
	 atmeans ///
	 dydx(sh_highrisk) by(hincfel) ///
	 predict(outcome(`o')) ///
		post
     eststo, title(Outcome `o')
	 estimates restore est1
     
 }
 
eststo drop est1


esttab using example.csv, replace nogap ///
star( + 0.10 * 0.05 ** 0.01 *** 0.001) ///
b(a3) se(a3) ///
nonumbers mtitles("RR" "RL" "ML" "MR" "Did not vote") /// 
stats(N, layout(`""@ (@)""' @ @)) varwidth(65) unstack label ///
title(Adjusted Marginal Effects)




***
// E12) Insider-outsider (Rueda binary)
eststo, title("Logit Regression"): ///
	mlogit vote_after_a ///
	c.sh_highrisk##ib3.hincfel ///
	c.age i.gender_b c.education ///
	c.rlgdgr i.union i.ethnic_min ///
	c.income ///
	i.year ///
	i.country_used ///
	i.emp_ctra ///
	[pweight=dweight], ///
	cluster(country_used) base(1) 

	
* Post-estimation Output
foreach o in 1 2 3 4 5  {
     quietly margins, ///
	 atmeans ///
	 dydx(sh_highrisk) by(hincfel) ///
	 predict(outcome(`o')) ///
		post
     eststo, title(Outcome `o')
	 estimates restore est1
     
 }
 
eststo drop est1


esttab using example.csv, replace nogap ///
star( + 0.10 * 0.05 ** 0.01 *** 0.001) ///
b(a3) se(a3) ///
nonumbers mtitles("RR" "RL" "ML" "MR" "Did not vote") /// 
stats(N, layout(`""@ (@)""' @ @)) varwidth(65) unstack label ///
title(Adjusted Marginal Effects)




*****
// E13) Income source
eststo, title("Logit Regression"): ///
	mlogit vote_after_a ///
	c.sh_highrisk##ib3.hincfel ///
	c.age i.gender_b c.education ///
	c.rlgdgr i.union i.ethnic_min ///
	c.income ///
	i.year ///
	i.country_used ///
	i.inc_src ///
	[pweight=dweight], ///
	cluster(country_used) base(1) 

	
* Post-estimation Output
foreach o in 1 2 3 4 5  {
     quietly margins, ///
	 atmeans ///
	 dydx(sh_highrisk) by(hincfel) ///
	 predict(outcome(`o')) ///
		post
     eststo, title(Outcome `o')
	 estimates restore est1
     
 }
 
eststo drop est1


esttab using example.csv, replace nogap ///
star( + 0.10 * 0.05 ** 0.01 *** 0.001) ///
b(a3) se(a3) ///
nonumbers mtitles("RR" "RL" "ML" "MR" "Did not vote") /// 
stats(N, layout(`""@ (@)""' @ @)) varwidth(65) unstack label ///
title(Adjusted Marginal Effects)


********************************************************************************
********************************************************************************

* F) Summary statistics
sum ///
	sh_highrisk ///
	vote_after_a ///
	hincfel ///
	age gender education ///
	rlgdgr union ethnic_min ///
	income year country_used dweight ///
	if country_used!=., 


	
	
*************Rehm Occupational Risk Measure******* based on Rehm 2009 CPS, straight from his data
********************************************************************
*gen isco88_1d=real(substr(string(iscoco),1,1))	// creates single-digit ISCO88 code 
gen isco88_1d = isco_1digit  //***here BEWARE that I am forcing ISCO88 to be based on ISCO08, however, seems fine at first digit. The EU Commission says: "The overall system of major groups, sub-major groups, minor groups and unit groups used in ISCO-88 has been retained in ISCO-08. The 10 major groups at the top level of the ISCO-08 structure are the same as those used in ISCO-88."(http://ec.europa.eu/eurostat/documents/1978984/6037342/Comparability_ISCO_08_ISCO_88.pdf) 
*generate generic year variable 
drop year
gen year=. 
replace year=2012 if essround==6
replace year=2014 if essround==7
replace year=2016 if essround==8


merge m:1 cntry year isco88_1d using "/Users/rovny/Google Drive/Documents/Sources/Datasets/Rehm's Occupational Unemployment Rates/Automation_paper_Rehm_data.dta" , force // this is the data that Philipp sent me directly. 
drop _merge
rename our prob_unempl  // variable of interest that measures the probability of being unemployed given respondent's occupation group at ISCO first digit.

corr sh_highrisk prob_unempl  if country_used!=.
reg prob_unempl sh_highrisk 	if country_used!=.



********************************************************************************
************************************** End *************************************
********************************************************************************
